package com.learn.rpc.version.version1;

import com.learn.rpc.common.AdminUser;
import com.learn.rpc.common.FinalParam;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * 进行直接远程RPC调用,通过字符串和基础类型数据进行二次拼接成对象
 * @author wangxing
 * @version 2020/8/15 7:03 Administrator
 */
public class RpcClient {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(FinalParam.HOST,FinalParam.PORT);
        process(socket);
        socket.close();
    }

    private static void process(Socket socket) throws IOException {
        DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
        dataOutputStream.writeInt(123);
        dataOutputStream.flush();

        DataInputStream dataInputStream = new DataInputStream(socket.getInputStream());
        Integer id = dataInputStream.readInt();
        String name = dataInputStream.readUTF();
        AdminUser adminUser = new AdminUser(id,name);
        System.out.println(adminUser);
        dataInputStream.close();
        dataOutputStream.close();

    }

}
